package com.eascs.web.o2o.web.controller;

import java.text.DecimalFormat;
import java.text.Format;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.eascs.app.dao.PageResult;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.common.util.UrlUtil;
import com.eascs.site.controller.BaseRestController;
import com.eascs.site.page.PaginationInfo;
import com.eascs.site.page.SelectDataOption;
import com.eascs.site.view.PaginationRestResult;
import com.eascs.site.view.ViewContext;
import com.eascs.web.context.RequestContext;
import com.eascs.web.o2o.web.aging.service.SysOrgService;
import com.eascs.web.o2o.web.form.LoanBeforeForm;
import com.eascs.web.o2o.web.service.ReportForLoanBeforeService;

/**
 * 业务运营分析（贷前数据）
 * @author Administrator
 *
 */
@RestController
@RequestMapping("/restLoanBefore")
public class ReportForLoanBeforeRestController extends BaseRestController {
	
	protected final Logger logger = LoggerFactory.getLogger(getClass());
	
	@Reference
	SysOrgService sysOrgService;
	
	@Autowired
	ReportForLoanBeforeService reportForLoanBeforeService;
	
	@RequestMapping(value="/loanBefore")
	public PaginationRestResult reportForLoanBeforePage(LoanBeforeForm entity) {
		String o2oUrl = "/restLoanBefore/loanBefore";
		if(entity != null) {
			String createDateStart = entity.getCreateDateStart();
			String createDateEnd = entity.getCreateDateEnd();
			String nsStartDateStart = entity.getNsStartDateStart();
			String nsStartDateEnd = entity.getNsStartDateEnd();
			String ssBankName = entity.getSsBankName();
			String zxBankName = entity.getZxBankName();
			String provinceName = entity.getProvinceName();
			String brandName = entity.getBrandName();
			o2oUrl = UrlUtil.appendUrl(o2oUrl, "createDateStart", createDateStart);
			o2oUrl = UrlUtil.appendUrl(o2oUrl, "createDateEnd", createDateEnd);
			o2oUrl = UrlUtil.appendUrl(o2oUrl, "nsStartDateStart", nsStartDateStart);
			o2oUrl = UrlUtil.appendUrl(o2oUrl, "nsStartDateEnd", nsStartDateEnd);
			o2oUrl = UrlUtil.appendUrl(o2oUrl, "ssBankName", ssBankName);
			o2oUrl = UrlUtil.appendUrl(o2oUrl, "zxBankName", zxBankName);
			o2oUrl = UrlUtil.appendUrl(o2oUrl, "provinceName", provinceName);
			o2oUrl = UrlUtil.appendUrl(o2oUrl, "brandName", brandName);
			o2oUrl = o2oUrl + "&o2oIndex=";
		} else {
			o2oUrl = o2oUrl + "&o2oIndex=";
		}
		entity.setPageSize(10);
		PageResult<Object[]> pageResult = reportForLoanBeforeService.loanBefore(entity);
		String[] titles = {"贷款单号", "省区", "征信银行", "送审银行", "内审提交时间", "品牌", "所属行业", "区域总监","信贷经理", "贷款类型", "申请状态", "缴纳状态", "申请金额(万元)", "创建时间"};
		SelectDataOption[] selectDataOptions = {new SelectDataOption("BANKTYPEO2O")};
		PaginationInfo paginationInfo = new PaginationInfo(pageResult, titles, UrlUtil.resetParam(RequestContext.getRequestUrlWithQueryString(), "showPage", ""));
		paginationInfo.setFirstRenderColumnIndex(0);
		paginationInfo.setSelectDataOptions(selectDataOptions);
		paginationInfo.setFormats(new Format[] { null, null, null, null, null, null, null, null, null, null ,null ,null ,new DecimalFormat(",##0.00"), null});
		paginationInfo.setRendTo("#o2o_result");
		ViewContext.put("vo", entity);
		return PaginationRestResult.buildPaginationRestResult(paginationInfo);
	}

}
